using UnityEngine.Events;

/// <summary>
/// UnityEvent扩展功能
/// </summary>
public static class UnityEventExtension
{
    /// <summary>
    /// 添加监听并且绑定一个参数对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="unityEvent"></param>
    /// <param name="action"></param>
    /// <param name="arg"></param>
    public static void ExAddListener<T>(this UnityEvent unityEvent, UnityAction<T> action, T arg)
    {
        unityEvent.AddListener(delegate () { action(arg); });
    }
    /// <summary>
    /// 添加监听并且绑定两个参数对象
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <param name="unityEvent"></param>
    /// <param name="action"></param>
    /// <param name="arg"></param>
    /// <param name="arg2"></param>
    public static void ExAddListener<T1, T2>(this UnityEvent unityEvent, UnityAction<T1, T2> action, T1 arg, T2 arg2)
    {
        unityEvent.AddListener(delegate () { action(arg, arg2); });
    }
    /// <summary>
    /// 添加监听并且绑定三个参数对象
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <param name="unityEvent"></param>
    /// <param name="action"></param>
    /// <param name="arg"></param>
    /// <param name="arg2"></param>
    /// <param name="arg3"></param>
    public static void ExAddListener<T1, T2, T3>(this UnityEvent unityEvent, UnityAction<T1, T2, T3> action, T1 arg, T2 arg2, T3 arg3)
    {
        unityEvent.AddListener(delegate () { action(arg, arg2, arg3); });
    }
}